/*
 * KeySequence.cpp
 *
 *  Created on: 2010-9-9
 *      Author: wenjian
 */

#include "KeySequence.h"

namespace Ed {

  KeySequence::KeySequence() {
  }

  KeySequence::KeySequence(int k1, int k2, int k3, int k4) {
    add(k1);
    add(k2);
    add(k3);
    add(k4);
  }

  KeySequence::KeySequence(const KeySequence& ks) {
    add(ks);
  }


  KeySequence::~KeySequence() {
  }

  void KeySequence::add(int key){
    if(key > 0){
      sequence.push_back(key);
    }
  }

  void KeySequence::add(const KeySequence &ks){
    sequence.insert(sequence.end(), ks.sequence.begin(), ks.sequence.end());
  }

  unsigned int KeySequence::size() const{
    return sequence.size();
  }

  bool KeySequence::empty() const{
    return sequence.empty();
  }

//  KeySequence::SequenceMatch KeySequence::matches(const KeySequence &seq, bool serial) const{
//    unsigned int psize = seq.size();
//    if(size() < psize){
//      return NoMatch;
//    }
//    // TODO ... 下一步实现
//    return NoMatch;
//  }

  bool KeySequence::test(int key) const{
    return find(sequence.begin(), sequence.end(), key) != sequence.end();
  }

  int KeySequence::operator[](unsigned int i) const{
    return sequence[i];
  }

  bool KeySequence::operator==(const KeySequence &other) const{
    if(this==&other){
      return true;
    }
    return sequence == other.sequence;
  }

}
